package com.jcnet.bizaia.fragment;

import java.util.List;

import com.jcnet.bizaia.DiscussDetialActivity;
import com.jcnet.bizaia.R;
import com.jcnet.bizaia.adapter.DiscussHistoryAdapater;
import com.jcnet.bizaia.adapter.DiscussYuGaoAdapater;
import com.jcnet.bizaia.bean.CompanyInfoBean;
import com.jcnet.bizaia.bean.DicussListForecast;
import com.jcnet.bizaia.bean.MainInfoBean;
import com.jcnet.bizaia.bean.TeacherInfoBean;

import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.DialogInterface.OnClickListener;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;
/**
 * @author chenguandong
 * @serial   主办方详细
 */
public final class ComperDetailFragment extends Fragment implements android.view.View.OnClickListener{
    private static final String KEY_CONTENT = "TestFragment:Content";

    private CompanyInfoBean chaCompanyJson;
    
    private View jcIntroView;
    
    
    private ListView yuGaoListView;
    
    private ListView historyListView;
    
    private List<DicussListForecast>yugaoDicussListForecasts;
    private List<DicussListForecast>historyDicussListForecasts;
    
    
    private Button button;
    private Button button2;
    private Button button3;
    
    private boolean isOpen1 = true;
    private boolean isOpen2 = true;
    private boolean isOpen3 = true;
    
    
    public static ComperDetailFragment newInstance(  CompanyInfoBean chaCompanyJson) {
        ComperDetailFragment fragment = new ComperDetailFragment();

       // fragment.mContent = builder.toString();
        fragment.chaCompanyJson = chaCompanyJson;
        return fragment;
    }


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        if ((savedInstanceState != null) && savedInstanceState.containsKey(KEY_CONTENT)) {
            //mContent = savedInstanceState.getString(KEY_CONTENT);
        }
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
       View view = View.inflate(getActivity(), R.layout.company_info, null);
       jcIntroView = view.findViewById(R.id.jcIntroView);
       
       ((TextView)view.findViewById(R.id.jcIntorText)).setText(
    		getString(R.string.cpName)+" "+chaCompanyJson.getCpname()+"\r\n"
    		+getString(R.string.adress)+" "+chaCompanyJson.getCpaddress()+"\r\n"
    		+getString(R.string.phone)+" "+chaCompanyJson.getCptel()+"\r\n"
    		+getString(R.string.cpManager)+" "+chaCompanyJson.getLealperson()+"\r\n"
    		+getString(R.string.cpBulid)+" "+chaCompanyJson.getCptime()+"\r\n"
    		+getString(R.string.cpMoney)+" "+chaCompanyJson.getCpmoney()+"\r\n"
    		+chaCompanyJson.getCpintro()+"\r\n"
    		   );
       
       yuGaoListView =(ListView)view.findViewById(R.id.yuGaoListView);
       
       historyListView = (ListView)view.findViewById(R.id.historyListView);
       
       button = (Button)view.findViewById(R.id.buttonMeetInfo);
       button2 = (Button)view.findViewById(R.id.buttonMeetForecast);
       button3 = (Button)view.findViewById(R.id.buttonMeetHistory);
       button.setOnClickListener(this);
       button2.setOnClickListener(this);
       button3.setOnClickListener(this);
       initData();
        return view;
    }

    private void initData() {
		// TODO Auto-generated method stub
    	yugaoDicussListForecasts = chaCompanyJson.getForeshowJson();
    	historyDicussListForecasts = chaCompanyJson.getListshowJson();
    	
    	 yuGaoListView.setAdapter(new DiscussYuGaoAdapater(getActivity()
      		   , yugaoDicussListForecasts));
         
         historyListView.setAdapter(new DiscussHistoryAdapater(getActivity(), historyDicussListForecasts));
         
         historyListView.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> parent, View view,
					int position, long id) {
				// TODO Auto-generated method stub
				DicussListForecast benForecast = historyDicussListForecasts.get(position);
				
				Intent intent = new Intent(getActivity(), DiscussDetialActivity.class);
				intent.putExtra("imgUrl", benForecast.getPictureurl());
				intent.putExtra("cridNum",benForecast.getFcrid());
				startActivity(intent);
				
			}
		});
    
    }


	@Override
    public void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
       // outState.putString(KEY_CONTENT, mContent);
    }

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.buttonMeetInfo:
			if(isOpen1){
				jcIntroView.setVisibility(View.VISIBLE);
				yuGaoListView.setVisibility(View.GONE);
				historyListView.setVisibility(View.GONE);
			}else{
				jcIntroView.setVisibility(View.GONE);
			}
			isOpen1 = !isOpen1;
			break;
		case R.id.buttonMeetForecast:
			if(isOpen2){
			jcIntroView.setVisibility(View.GONE);
			yuGaoListView.setVisibility(View.VISIBLE);
			historyListView.setVisibility(View.GONE);
			}else{
				yuGaoListView.setVisibility(View.GONE);
			}
			isOpen2 = !isOpen2;
			break;
		case R.id.buttonMeetHistory:
			if(isOpen3){
			jcIntroView.setVisibility(View.GONE);
			yuGaoListView.setVisibility(View.GONE);
			historyListView.setVisibility(View.VISIBLE);
			}else{
				historyListView.setVisibility(View.GONE);
			}
			
			isOpen3 = !isOpen3;
			break;

		default:
			break;
		}
	}
}
